package com.example.user.web;


import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;


@RestController
public class UserAcrion {


    @RequestMapping("user")
    public  String user(HttpServletRequest request){
        return "user: "+request.getServerPort();
    }


    @Resource
    RestTemplate restTemplate;
    @RequestMapping("index")
    public String user(){
        String ret = restTemplate.getForObject("http://index/index", String.class);
        return "远程访问index:"+ret;
    }


    @RequestMapping("hello")
    public String hello(String name){
        return "hello"+name;
    }

    @RequestMapping("add")
    public int add(int a, int b){
        return a+b;
    }


    @RequestMapping("reg")
    public User reg(@RequestBody User user){
        user.setName(user.getName()+"xxx");
        return user;
    }

    @RequestMapping("path/{ptest}")
    public String ptest(@PathVariable("ptest") String ptest){
        return ptest+"demo";
    }

}

